Page({
  data: {
    content: '',
    order_id: '', //订单ID
    wid: '', //家政员ID
    money: '',
    type: '2', //1服务 2套餐
    do: 'OrderInfo',
    aunt: {
      avatar: '',
      user_nickname: ''
    },
    list: [{
        title: '服务评价',
        score: 5
      },
      {
        title: '店铺评价',
        score: 5
      },
      {
        title: '家政员评价',
        score: 5
      }
    ]
  },
  onLoad: function (options) {
    if (options.type) {
      this.setData({
        type: options.type,
        do: options.type==2?'OrderInfo':'Workinfo',
        wid: options.id,
        order_id: options.id,
      })
    } else {
      this.setData({
        order_id: options.id,
      })
    }
    this.getList()
  },
  getrate(e) { //选择星级
    console.log(e)
    let val = 'list[' + e.currentTarget.dataset.index + '].score'
    this.setData({
      [val]: e.detail.score
    })
  },
  bindTextAreaBlur: function (e) { //评价内容
    this.setData({
      content: e.detail.value
    })
  },
  getList() { //获取信息
    getApp().globalData.post({
      data: {
        do: this.data.do,
        order_id: this.data.order_id,
        wid: this.data.wid
      }
    }).then(res => {
      this.setData({
        aunt: res.data.good ? res.data.good[0] : res.data.data,
        money: res.data.good ? res.data.good[0].money : res.data.data.money,
        spec: res.data.good ? res.data.good[0].spec : ''
      })
    })
  },
  submit() { //提交评价
    if (this.data.content == '') {
      wx.showToast({
        title: '评价内容不能为空',
        icon: 'none'
      })
      return false
    }
    getApp().globalData.post({
      data: {
        do: "Evaluate",
        type: this.data.type,
        uid: wx.getStorageSync('userInfo').id,
        order_id: this.data.order_id,
        service_score: this.data.list[0].score,
        shop_score: this.data.list[1].score,
        aunt_score: this.data.list[2].score,
        content: this.data.content
      }
    }).then(res => {
      getApp().showModal(res.data.msg).then(() => {
        if (res.data.status == 1) {
          if (this.data.type == 2) {
            wx.reLaunch({
              url: './index',
            })
          } else {
            wx.reLaunch({
              url: './order',
            })
          }
        }
      })
    })
  }
})